/**
 * 添加按钮操作
 */
$("#button-add").click(function () {
    var url = SCOPE.add_url;
    window.location.href = url;
});
/**
 * 提交form表单操作
 */
$("#singcms-button-submit").click(function () {
    var data = $("#singcms-form").serializeArray();
    postData = {};
    $(data).each(function (i) {
        postData[this.name] = this.value;
    });
    //将获取到的数据post到服务器  这里的变量不用var
     url = SCOPE.save_url;
     jump_url = SCOPE.jump_url;
    $.post(url , postData , function (resoult) {
        if (resoult.status == 1){
            return dialog.success(resoult.msg , jump_url);
        }else if (resoult.status == 0){
            return dialog.error(resoult.msg)
        }
    } , 'json');
});
/**
 * 修改，编辑
 */
$(".singcms-table #singcms-edit").click(function () {
    var id = $(this).attr('attr-id');
    var url = SCOPE.edit_url + '&id=' + id;
    window.location.href = url;
});
/**
 *删除操作
 */
$('.singcms-table #singcms-delete').click(function () {
    var id = $(this).attr('attr-id');
    var a = $(this).attr('attr_a');
    var message = $(this).attr('attr-message');
    var url = SCOPE.set_status_url;
    //ajax提交数据
    data = {};
    data['id'] = id;
    data['status'] = -1;
    layer.open({
        type : 0 ,
        title : '是否提交' ,
        btn : ['yes' , 'no'],
        icon : 3 ,
        closeBtn : 2 ,
        content : '是否确定' + message ,
        scrollbar :  true ,
        yes : function(){
            //执行跳转
            todelete(url , data);
        },
    });
});
/**
 * 执行删除
 * @param url
 * @param data
 */
function todelete(url , data) {
    $.post(
        url ,
        data ,
        function (s) {
            if (s.status == 1){
                return dialog.success(s.msg , '');
            }else{
                return dialog.error(s.msg);
            }
        }
     , 'json');
}
/**
 * 进行排序
 */
$('#button-listorder').click(function () {
    var data = $('#singcms-listorder').serializeArray();
    var  postData = {};
    // console.log(data);
    $(data).each(function (i) {
        postData[this.name] = this.value;
    });
    var url = SCOPE.listorder_url;
    $.post(
        url,
        postData,
        function (s) {
            if (s.status == 1){
                return dialog.success(s.msg , s['data']['jump_url']);
            }else{
                return dialog.error(s.msg , s['data']['jump_url']);
            }
        }
    ,  'json');
});
/**
 * 修改文章状态
 */
$('.singcms-table #singcms-on-off').click(function () {
    var id = $(this).attr('attr-id');
    var status = $(this).attr('attr-status');
    var url = SCOPE.set_status_url;

    data = {};
    data['id'] = id;
    data['status'] = status;
    // console.log(data);
    layer.open({
        type : 0 ,
        title : '是否提交' ,
        btn : ['yes' , 'no'],
        icon : 3 ,
        closeBtn : 2 ,
        content : '是否确定更改状态？' ,
        scrollbar :  true ,
        yes : function(){
            //执行跳转
            todelete(url , data);
        },
    });
});
/**
 * js实现推送相关代码
 */
$("#singcms-push").click(function () {
    //推荐位ID
    var id = $("#select-push").val();
    if (id == 0){
        return dialog.error("请选择推荐位");
    }
    var push = {};
    var postData = {};
    //获取文章的ID
    $("input[name='pushcheck']:checked").each(function (i) {
        push[i] = $(this).val();
    });
    postData['push'] = push;
    postData['position_id'] = id;
    //打印数据
    // console.log(postData);
    var url = SCOPE.push_url;
    $.post(url , postData , function (res) {
        if (res.status ==  1){
            // console.log(res);
            return dialog.success(res.msg , res['data']['jump_url']);
        }else if (res.status == 0){
            return dialog.error(res.msg)
        }
    } , 'json');
});













